// pages/mine/myAnswer/myAnswer.js

let {
  api_GetUserAnswer,
  api_GetTopicByTopicid
} = require("../../api/getData.js")
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userAnswer:[],
    userInfo:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var data = {
      userid: app.globalData.userInfo.id,
    }
    api_GetUserAnswer(data, (res) => {
      var arrayTmp = [];
      res.data.forEach(i => {
        arrayTmp.push(i)
      })
      this.setData({
        userAnswer: arrayTmp,
        userInfo: app.globalData.userInfo
      })
      console.log(this.data.userInfo)
    })
  },

  bindMakeComment: function (e) {
    var answer = e.currentTarget.dataset.index;
    var data = {
      topicid:answer.topicId,
    }
    api_GetTopicByTopicid(data, (res) => {
      var topic = res.data;
      var imgUrlList = []
      for (var m = 0; m < topic.piclen; m++) {
        imgUrlList.push(app.globalData.static_url + "topic/" + topic.id + "/" + (m + 1) + ".png")
      }
      topic.imgUrlList = imgUrlList;
      var dataTmp = JSON.stringify(topic)
      wx.navigateTo({
        url: '../../mine/question/question?topic=' + dataTmp,
        success: function (res) {
          // success
        },
        fail: function () {
          // fail
        },
      })
    })
  },

})